﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataModel
{
    public class SiteColumnType
    {
        //Static list of predefined column types
        private static SiteColumnType[] types = {
            new SiteColumnType("Single line of text", "SingleLineText", new String[]{"Text"}),
            new SiteColumnType("Multiple lines of text", "MultiLineText",  new String[]{"Note"}),
            new SiteColumnType("Choice (menu to choose one item from)", "Choice",  new String[]{"Choice"}),
            new SiteColumnType("Multi-Choice (menu to choose one or more items from)", "MultiChoice",  new String[]{"MultiChoice"}),
            new SiteColumnType("Number (1, 1.0, 100)", "Number",  new String[]{"Number", "Integer"}),
            new SiteColumnType("Currency ($, ¥, €)", "Currency",  new String[]{"Currency"}),
            new SiteColumnType("Date and Time", "DateTime",  new String[]{"DateTime"}),
            new SiteColumnType("Lookup (information already on this site)", "Lookup",  new String[]{"Lookup", "LookupFieldMulti"}),
            new SiteColumnType("Yes/No (check box)", "Boolean",  new String[]{"Boolean"}),
            new SiteColumnType("Person or Group", "User",  new String[]{"User"}),
            new SiteColumnType("Hyperlink or Picture", "HyperlinkOrPicture",  new String[]{"HyperlinkOrPicture"}),
            new SiteColumnType("Calculated (calculation based on other columns)", "Calculated",  new String[]{"Calculated", "Computed"}),
            new SiteColumnType("Task Outcome", "TaskOutcome",  new String[]{"TaskOutcome"}),
            new SiteColumnType("Full HTML content with formatting and constraints for publishing", "FullHtmlContent",  new String[]{"FullHtmlContent"}),
            new SiteColumnType("Image with formatting and constraints for publishing", "Image",  new String[]{"Image"}),
            new SiteColumnType("Hyperlink with formatting and constraints for publishing", "Link",  new String[]{"Link", "URL"}),
            new SiteColumnType("Summary Links data", "SummaryLinks",  new String[]{"SummaryLinks"}),
            new SiteColumnType("Rich media data for publishing", "Media",  new String[]{"Media"}),
            new SiteColumnType("Managed Metadata", "ManagedMetaData",  new String[]{"TaxonomyFieldTypeMulti", "TaxonomyFieldType"})
        };
        public static SiteColumnType[] Types { get { return types; } set { } }
        
        public static SiteColumnType SINGLE_LINE_OF_TEXT = types[0];
        public static SiteColumnType MULTIPLES_LINES_OF_TEXT = types[1];
        public static SiteColumnType CHOICE = types[2];
        public static SiteColumnType MULTICHOICE = types[3];
        public static SiteColumnType NUMBER = types[4];
        public static SiteColumnType CURRENCY = types[5];
        public static SiteColumnType DATE_AND_TIME = types[6];
        public static SiteColumnType LOOKUP = types[7];
        public static SiteColumnType YES_NO = types[8];
        public static SiteColumnType PERSON_OR_GROUP = types[9];
        public static SiteColumnType HYPERLINK_OR_PICTURE = types[10];
        public static SiteColumnType CALCULATED = types[11];
        public static SiteColumnType TASK_OUTCOME = types[12];
        public static SiteColumnType FULL_HTML_WITH_FORMATTING = types[13];
        public static SiteColumnType IMAGE_WITH_FORMATTING = types[14];
        public static SiteColumnType HYPERLINK_WITH_FORMATTING = types[15];
        public static SiteColumnType SUMMARY_LINKS_DATA = types[16];
        public static SiteColumnType RICH_MEDIA_DATA = types[17];
        public static SiteColumnType MANAGED_METADATA = types[18];

        public static SiteColumnType GetTypeByShortName(String name)
        {
            try
            {
                return types.Single(SiteColumnType => SiteColumnType.shortName == name);
            }
            catch
            {
                //Log.Append("SiteColumnType.GetTypeByShortName -- Could not find Column Type by name: " + name).AppendLine();
                throw new Exception("SiteColumnType.GetTypeByShortName -- Could not find Column Type by name: " + name);
            }
        }
        public static SiteColumnType GetTypeByLongName(String name)
        {
            try
            {
                return types.Single(SiteColumnType => SiteColumnType.longName == name);
            }
            catch
            {
                //Log.Append("SiteColumnType.GetTypeByLongName -- Could not find Column Type by name: " + name).AppendLine();
                throw new Exception("SiteColumnType.GetTypeByLongName -- Could not find Column Type by name: " + name);
            }
        }

        public static SiteColumnType GetTypeBySPName(String name)
        {
            try
            {
                return types.Single(SiteColumnType => SiteColumnType.spNames.Contains(name));
            }
            catch
            {
                //Log.Append("SiteColumnType.GetTypeBySPName -- Could not find Column Type by name: " + name).AppendLine();
                throw new Exception("SiteColumnType.GetTypeBySPName -- Could not find Column Type by name: " + name);
            }
        }
        // the non-static stuff
        private String longName;
        private String shortName;
        private String[] spNames;

        public String LongName { get { return longName; } set { } }
        public String ShortName { get { return shortName; } set { } }
        public String[] SPNames { get { return spNames; } set { } }

        private SiteColumnType(String longName, String shortName, String[] spNames)
        {
            this.longName = longName;
            this.shortName = shortName;
            this.spNames = spNames;
        }

        public override string ToString()
        {
            return longName;
        }
    }
}
